﻿<template>
  <a-modal :title="title" width="40%" :visible="visible" :confirmLoading="loading" @ok="handleSubmit"
    @cancel="() => { this.visible = false }">
    <a-spin :spinning="loading">
      <a-form-model ref="form" :model="entity" :rules="rules" v-bind="layout">
        <a-form-model-item label="接口名称" prop="InterfaceName">
          <a-input v-model="entity.InterfaceName" autocomplete="off" />
        </a-form-model-item>
        <a-form-model-item label="日志类型" prop="LogType">
          <a-input v-model="entity.LogType" autocomplete="off" />
        </a-form-model-item>
        <a-form-model-item label="日志内容" prop="LogContent">
          <a-input v-model="entity.LogContent" autocomplete="off" />
        </a-form-model-item>
        <a-form-model-item label="接口数据" prop="InterfaceData">
          <a-input v-model="entity.InterfaceData" autocomplete="off" />
        </a-form-model-item>
      </a-form-model>
    </a-spin>
  </a-modal>
</template>

<script>
export default {
  props: {
    parentObj: Object
  },
  data() {
    return {
      layout: {
        labelCol: { span: 5 },
        wrapperCol: { span: 18 }
      },
      visible: false,
      loading: false,
      entity: {},
      rules: {},
      title: ''
    }
  },
  methods: {
    init() {
      this.visible = true
      this.entity = {}
      this.$nextTick(() => {
        this.$refs['form'].clearValidate()
      })
    },
    openForm(id, title,selectedRows) {
      this.init()
      if (id) {
        this.loading = true
        this.$http.post('/Base_Manage/Base_InterfaceLog/GetTheData', { id: id }).then(resJson => {
          this.loading = false
          this.entity = resJson.Data
        })
      }
      else {
        if (selectedRows.length > 0 && title==='Add') {
          this.entity = selectedRows[0];
          this.entity.Id='';
        }
      }

    },
    handleSubmit() {
      this.$refs['form'].validate(valid => {
        if (!valid) {
          return
        }

        this.loading = true
        this.$http.post('/Base_Manage/Base_InterfaceLog/SaveData', this.entity).then(resJson => {
          this.loading = false

          if (resJson.Success) {
            this.$message.success('操作成功!')
            this.visible = false

            this.parentObj.getDataList()
          } else {
            this.$message.error(resJson.Msg)
          }
        })
      })
    }
  }
}
</script>
